package com.ruoyi.wuliu.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.wuliu.domain.TraceTransport;
import com.ruoyi.wuliu.service.TraceTransportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @projectName: BlockchainFabric
 * @package: com.ruoyi.wuliu.controller
 * @className: WuLiuController
 * @author: 张雅妮
 * @description: TODO
 * @date: 2023/5/19 16:13
 * @version: 1.0
 */
@RequestMapping("wuliu")
@RestController
@CrossOrigin
public class WuLiuController {

    @Autowired
    TraceTransportService traceTransportService;

    /**
     * 物流代办列表
     * @return
     */
    @RequestMapping("list")
    public R list(){
        List<TraceTransport> list = traceTransportService.list();
        return R.ok(list);
    }

    /**
     * 配送货物
     * @param id
     * @return
     */
    @RequestMapping("updatestatus")
    public R updatestatus(Integer id){
        TraceTransport traceTransport = traceTransportService.getById(id);
        traceTransport.setStatus(1);//正在运输
        boolean b = traceTransportService.updateById(traceTransport);
        return b?R.ok():R.fail();
    }

    /**
     * 运输完毕
     * @param id
     * @return
     */
    @RequestMapping("wanbi")
    public R wanbi(Integer id){
        TraceTransport traceTransport = traceTransportService.getById(id);
        traceTransport.setStatus(2);//运输完毕
        boolean b = traceTransportService.updateById(traceTransport);
        return b?R.ok():R.fail();
    }

    /**
     * 查询申请两天还未发货物流列表
     */
    @RequestMapping("listByTimeAndStatus")
    public List<TraceTransport> listByTimeAndStatus(){
        return traceTransportService.listByTimeAndStatus();
    }

}
